<%@page import="models.User"%>
<%@page import="java.util.TreeMap"%>
<%@page import="models.Blog"%>
<%@page import="models.AutoSite"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.net.URLEncoder"%>
<%
	ArrayList<AutoSite> sites = (ArrayList<AutoSite>) request.getAttribute("sites");
	AutoSite autoSite = (AutoSite) request.getAttribute("autoSite");
	Blog blog = (Blog) request.getAttribute("blog");
	TreeMap check = (TreeMap) request.getAttribute("check");
	String success = (String) request.getAttribute("success");
	String form = (String) request.getAttribute("form");
	User user = (User) request.getAttribute("user");
%>

<jsp:include page="/layouts/header.jsp">
	<jsp:param name="title" value="" />
	<jsp:param name="description" value="" />
	<jsp:param name="keywords" value="" />
	<jsp:param name="page" value="home" />
</jsp:include>

<div id="userform" class="clearafter">
	<h1>Get Auto Content</h1><hr/>
	<div class="submitlink">
		<form method="post" action="" name="submitlink">
			<%=success != null ? "<p class=\"msg-success\">" + success + "</p>" : "" %>
			<% if (check.get("limitSite") != null) { %>
				<span class="error"><%=check.get("limitSite")%></span><br />
			<% } %>
			<% if (form != null && form.equals("edit")) { %>
				<a onclick="javascript:if(!confirm('Do you want delete ?'))return false;" style="font-size: 20px;" href="/delete-site?siteId=<%=autoSite.getId()%>">Delete</a>
			<% } %>
			<p>
				<% if (check.get("site") != null) { %>
					<span class="error"><%=check.get("site")%></span><br />
				<% } %>
				
				<label> 
					Sitemaps 
					<% if (form != null && !form.equals("edit")) { %> 
					&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
					<% } %>
					<span class="note">
						Add Url of Site that you want to auto get Content.
					</span>
					<% if (form != null && form.equals("edit")) { %>
					<br /> <b style="font-size: 25px;"><%=autoSite.getSite() %> </b>
					<input class="input" type="hidden" name="site" id="site" value="<%=autoSite.getSite()%>"/>
					<% } else { %>
					<br /> <input class="input" type="text" name="site" id="site" value="<%=autoSite.getSite()%>"/> 
					<% } %>
				</label>
				
			</p>
			<p>
				<div style="border: 1px solid #CCC;margin-bottom: 10px;padding: 5px;max-height: 300px;overflow: auto;width: 96%;" id='showreg'></div>
			</p>
			<p>
				HTML <input class="input type" type="radio" name="typeSource"  style="width: auto;"  value="html" 
					<%=autoSite.getTypeSource().equalsIgnoreCase("html") ? "checked=\"checked\"" : "" %> >&nbsp;&nbsp;&nbsp;&nbsp;
				RSS <input class="input type" type="radio" name="typeSource"  style="width: auto;" value="rss" 
					<%=autoSite.getTypeSource().equalsIgnoreCase("rss") ? "checked=\"checked\"" : "" %> disabled="disabled">&nbsp;&nbsp;&nbsp;&nbsp;
				XML <input class="input type" type="radio" name="typeSource"  style="width: auto;" value="xml" 
					<%=autoSite.getTypeSource().equalsIgnoreCase("xml") ? "checked=\"checked\"" : "" %> disabled="disabled">&nbsp;&nbsp;&nbsp;&nbsp;
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question" />
				<span class="note">
					Content contain Html, Rss or XML. Best to choose Html.
				</span>	
			</p>
			<p>
				Publish:
				Yes <input class="input type" type="radio" name="published"  style="width: auto;"  value="true" 
					<%=autoSite.getPublished() == true ? "checked=\"checked\"" : "" %>/>&nbsp;&nbsp;&nbsp;&nbsp;
				No <input class="input type" type="radio" name="published"  style="width: auto;" value="false" 
					<%=autoSite.getPublished() == false ? "checked=\"checked\"" : "" %>/>
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Auto publish content or not publish on blog.
				</span>	
			</p>
			<p>
				Source : 
				Yes <input class="input type" type="radio" name="displaySource"  style="width: auto;"  value="true" 
					<%=autoSite.getDisplaySource() == true ? "checked=\"checked\"" : "" %>/>&nbsp;&nbsp;&nbsp;&nbsp;
				No <input class="input type" type="radio" name="displaySource"  style="width: auto;" value="false" 
					<%=autoSite.getDisplaySource() == false ? "checked=\"checked\"" : "" %>/>
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Display from Source by choose Yes and don't display from source by choose No
				</span>	
			</p>
			<p>
				Get Page:
				Yes <input class="input type" type="radio" name="getPage"  style="width: auto;"  value="true" 
					<%=autoSite.isGetPage() == true ? "checked=\"checked\"" : "" %>/>&nbsp;&nbsp;&nbsp;&nbsp;
				No <input class="input type" type="radio" name="getPage"  style="width: auto;" value="false"
					<%=autoSite.isGetPage() == false ? "checked=\"checked\"" : "" %>/>
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Auto get content with all content page.
				</span>	
			</p>
			<p>
				<% if (check.get("regLink") != null) { %>
					<span class="error"><%=check.get("regLink")%></span><br />
				<% } %>
				<label> Selector of Title Link
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Choose Newest Article of Blog. Then, Input Selector format tag to get Title Link: "class" by "." + name of class - "id" by "#" + name of id . Example : http://abc.com/getSelector
				</span>
				<br /> <input class="input" type="text" name="regLink" id="reg-link" value="<%=autoSite.getRegLink()%>"/> </label>
			</p>
			<p>
				<% if (check.get("regTitle") != null) { %>
					<span class="error"><%=check.get("regTitle")%></span><br />
				<% } %>
				<label> Selector of Title
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Click to the tilte link to redirect details page that you chose Newest Article. Then, input Selector format tag to get Title.
				</span>
				<br /> <input class="input" type="text" name="regTitle" id="reg-title" value="<%=autoSite.getRegTitle()%>"/> </label>
			</p>
			<p>
				<% if (check.get("regContent") != null) { %>
					<span class="error"><%=check.get("regContent")%></span><br />
				<% } %>
				<label> Selector of Content
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Input Selector format tag to get Content of Newest Article.
				</span>
				<br /> <input class="input" type="text" name="regContent" id="reg-content" value="<%=autoSite.getRegContent()%>"/> </label>
			</p>
			<p>
				<% if (check.get("regRemove") != null) { %>
					<span class="error"><%=check.get("regRemove")%></span><br />
				<% } %>
				<label> Selector To Remove
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Input Selector format tag to remove a part of Content of Newest Article that you don't want. 
				</span>
				<br /> <input class="input" type="text" name="regRemove" id="reg-remove" value="<%=autoSite.getRegRemove()%>"/> </label>
			</p>
			<p>
				<label> Status <br />
					<select name="status" class="input type" >
						<option value="0" <%=autoSite.getStatus()==0 ? "selected=\"selected\"" : "" %>>Inactive</option>
						<option value="1" <%=autoSite.getStatus()==1 ? "selected=\"selected\"" : "" %>>Active</option>
					</select>
				</label>
			</p>
			<p>
				<% if (check.get("scheduleSite") != null) { %>
					<span class="error"><%=check.get("scheduleSite")%></span><br />
				<% } %>
				<label> Time Schedule
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Time schedule for get content auto. it has unit is minute.
				</span>
				<br />
				<select class="input" name="scheduleSite" id="schedule-site">
					<option value="60" <%=autoSite.getScheduleSite() == 60 ? "selected=\"selected\"" : "" %>>1 hour</option>
					<option value="120" <%=autoSite.getScheduleSite() == 120 ? "selected=\"selected\"" : "" %>>2 hour</option>
					<option value="180" <%=autoSite.getScheduleSite() == 180 ? "selected=\"selected\"" : "" %>>3 hour</option>
					<option value="360" <%=autoSite.getScheduleSite() == 360 ? "selected=\"selected\"" : "" %>>6 hour</option>
					<option value="720" <%=autoSite.getScheduleSite() == 720 ? "selected=\"selected\"" : "" %>>12 hour</option>
					<option value="1080" <%=autoSite.getScheduleSite() == 1080 ? "selected=\"selected\"" : "" %>>18 hour</option>
					<option value="1440" <%=autoSite.getScheduleSite() == 1440 ? "selected=\"selected\"" : "" %>>24 hour</option>
				</select>
				</label>
			</p>
			<p>
				<% if (check.get("category") != null) { %>
					<span class="error"><%=check.get("category")%></span><br />
				<% } %>
				<label> Category
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Label for content get from this source.
				</span>
				<br /> <input class="input" type="text" name="category" id="category" value="<%=autoSite.getCategory()%>"/> </label>
			</p>
			<p class="page">
				<% if (check.get("scheduleSitePage") != null) { %>
					<span class="error"><%=check.get("scheduleSitePage")%></span><br />
				<% } %>
				<label> Time schedule Page
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Time schedule page for get content auto. it has unit is minute.
				</span>
				<br /> 
				<select class="input" name="scheduleSitePage" id="schedule-site-page">
					<option value="60" <%=autoSite.getScheduleSitePage() == 60 ? "selected=\"selected\"" : "" %>>1 hour</option>
					<option value="120" <%=autoSite.getScheduleSitePage() == 120 ? "selected=\"selected\"" : "" %>>2 hour</option>
					<option value="180" <%=autoSite.getScheduleSitePage() == 180 ? "selected=\"selected\"" : "" %>>3 hour</option>
					<option value="360" <%=autoSite.getScheduleSitePage() == 360 ? "selected=\"selected\"" : "" %>>6 hour</option>
					<option value="720" <%=autoSite.getScheduleSitePage() == 720 ? "selected=\"selected\"" : "" %>>12 hour</option>
					<option value="1080" <%=autoSite.getScheduleSitePage() == 1080 ? "selected=\"selected\"" : "" %>>18 hour</option>
					<option value="1440" <%=autoSite.getScheduleSitePage() == 1440 ? "selected=\"selected\"" : "" %>>24 hour</option>
				</select>
				</label>
			</p>
			<p class="page">
				<% if (check.get("sitePage") != null) { %>
					<span class="error"><%=check.get("sitePage")%></span><br />
				<% } %>
				<label> Site pages
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Add Url of Site that you want to auto get site page content.
				</span>
				<br /> <input class="input" type="text" name="sitePage" id="site-page" value="<%=autoSite.getSitePage()%>"/> </label>
			</p>
			<p class="page">
				<% if (check.get("currentPage") != null) { %>
					<span class="error"><%=check.get("currentPage")%></span><br />
				<% } %>
				<label> Current Page
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Current page which site had get auto content.
				</span>
				<br /> <input class="input" type="text" name="currentPage" id="current-page" value="<%=autoSite.getCurrentPage()%>"/> </label>
			</p>
			<p class="page">
				<% if (check.get("totalPage") != null) { %>
					<span class="error"><%=check.get("totalPage")%></span><br />
				<% } %>
				<label> Total Page
				&nbsp;<img alt="Question" src="/images/i-help.gif" class="question"/>
				<span class="note">
					Total page which site will get auto content.
				</span>
				<br /> <input class="input" type="text" name="totalPage" id="total-page" value="<%=autoSite.getTotalPage()%>"/> </label>
			</p>
			<p>
				<input type="submit" value="submit" />
				&nbsp;
				<input type="reset" value="reset" style="margin-left: 20px;"/>
			</p>
			<a href="javascript:void(0)" id="checklink">Preview Article</a> First, previewing your Article is ok before click Submit Button
		</form>
	</div>
	<div class="howdy">
		<h2 class="title">Hi, <%=user.getName() != null ? user.getName() : "" %></h2>
		Blog: <b><%=blog.getBlogId() %></b> <br />
		Type: <b><%=blog.getType() %></b> <br />
		User: <b><%=blog.getUsername() %></b> <br />
		<div class="bt-line"></div>
		<ul class="option">
			<li><a href="/add-blog">Add blog</a></li>
			<% if (form != null && form.equals("edit")) { %>
			<li><a href="/add-site?blogId=<%=blog.getBlogId()%>">Add Content Site</a></li>
			<% } %>
			<li><a href="/get-content?blogId=<%=blog.getBlogId()%>">Get Special Content</a></li>
			<li><a href="/view-profile">View profile</a></li>
			<li><a href="/logout">Logout</a></li>
		</ul>
		<h2 class="title" style="padding-top: 20px;">List sites</h2>
		<div class="listlink">
			<ul>
				<% for (int i = 0; i < sites.size(); i++) { %>
					<li><a class="site-icon <%=sites.get(i).getStatus()==0 ? "inactive" : "" %>" style="background-image: url('https://s2.googleusercontent.com/s2/favicons?domain_url=<%=sites.get(i).getSite()%>');"
							href="/view-site?siteId=<%=URLEncoder.encode(sites.get(i).getId())%>"><%=sites.get(i).getSite() %></a></li>
				<% } %>
			</ul>
		</div>
	</div>
	<div class="clearbreak"></div>
	<hr />
	<div class="checkresult">
		
	</div>
</div>
<script type="text/javascript">
<!--
 var blogId = "<%=blog.getBlogId()%>";
//-->
</script>
<script type="text/javascript" src="/js/form_site.js"></script>
<%@ include file='/layouts/footer.jsp'%>